from selenium import webdriver
from page.base_page.page_add_pd import PageAddPD
from page.base_page.page_zentao import PageZenTaoLogin
from page.base_page.page_base import PageBase
import page
import time
import pytest

@pytest.fixture(scope="function")
def driver(request):
    # options = webdriver.ChromeOptions()
    # options.add_argument('--headless')  #设置无头浏览器请求模式
    # options.add_argument("--disable-extensions")
    # options.add_argument("--disable-gpu")
    # options.add_argument("--no-sandbox") # linux中不写会报错
    # driver = webdriver.Chrome(options=options)
    driver = webdriver.Chrome()
    driver.maximize_window()
    driver.get(page.url)

    def close():
        time.sleep(5)
        driver.quit()

    request.addfinalizer(close)
    return driver

# 登录
@pytest.fixture(scope="function")
def login(driver):
    web = PageZenTaoLogin(driver)
    web.login()
    time.sleep(2)
    return driver

# 代替实例化（等同于pageaddpd=PageAddPD()）
@pytest.fixture(scope="function")
def pageaddpd(login):
    return PageAddPD(login)